package com.siki.www.clock.controller;


import com.siki.salessystemcommon.utils.SystemMsgJsonResponse;
import com.siki.www.clock.dto.SubmitClockInfoDTO;
import com.siki.www.clock.service.ClockService;
import com.siki.www.clock.vo.ClockInfoByDateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Siki in 2021/6/19
 */
@RestController
@Api(tags = "打卡操作相关接口")
@RequestMapping("/api/vi/siki/clock")
@CrossOrigin
public class ClockController {

    private final ClockService clockService;

    public ClockController(ClockService clockService) {
        this.clockService = clockService;
    }

    @PostMapping("/submit")
    @ApiOperation(value = "提交打卡接口", httpMethod = "POST")
    public SystemMsgJsonResponse submit(@Validated @RequestBody SubmitClockInfoDTO dto) {
        clockService.insertClockInfo(dto);
        return SystemMsgJsonResponse.success();
    }

    @GetMapping("/getInfo")
    @ApiOperation(value = "查询打卡信息", httpMethod = "GET", response = ClockInfoByDateVO.class)
    public SystemMsgJsonResponse getInfo(Authentication auth) {
        return SystemMsgJsonResponse.success(clockService
                .getSubmitInfoByDate(auth.getName()));
    }

    @GetMapping("/getRecord")
    @ApiOperation(value = "查询前一次的打卡记录", httpMethod = "GET", response = ClockInfoByDateVO.class)
    public SystemMsgJsonResponse getRecord(Authentication auth) {
        return SystemMsgJsonResponse.success(clockService.getRecord(auth.getName()));
    }
}
